package collections.queue;

import org.junit.Test;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

public class BlockingQueueDemo {

  static LinkedBlockingQueue<Integer> linkedBlockingQueue = new LinkedBlockingQueue(2);

  @Test
  public void test1() {
    linkedBlockingQueue.offer(1);
    linkedBlockingQueue.offer(2);
    try {
      // put take 是阻塞方法
      linkedBlockingQueue.put(3);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    List<Integer> l = new LinkedList<>();
    linkedBlockingQueue.drainTo(l);
    System.out.println(l);
    Object poll = linkedBlockingQueue.poll();
    System.out.println(poll);

  }

  @Test
  public void test2() {
    linkedBlockingQueue.offer(1);
    linkedBlockingQueue.offer(2);
    // put take 是阻塞方法
    linkedBlockingQueue.offer(3);
    List<Integer> l = new LinkedList<>();
    linkedBlockingQueue.drainTo(l);
    System.out.println(l);
    Object poll = linkedBlockingQueue.poll();
    System.out.println(poll);

  }

  public static void main(String[] args) {
    long currentTimeMillis = System.currentTimeMillis();
    System.out.println(currentTimeMillis);
    System.out.println(5000 - currentTimeMillis %1000);
  }

}
